<?php

namespace App\Http\Controllers\Client;

use App\Http\Controllers\Controller;
use App\Models\yb\ActivityModel;
use Illuminate\Http\Request;

class ActivityController extends Controller
{

    /**
     * Get a JWT via given credentials.
     *  活动列表
     * @return \Illuminate\Http\JsonResponse
     */
    public function listing(Request $request)
    {

        $page = $request->post('page', 1);
        $take = $request->post('take', 10);

        $data = ActivityModel::where(['status'=>1])->orderBy('created_at','desc')->skip(($page - 1) * $take)->take($take)->get();
        foreach($data as $key=>$val){
            $data[$key]['cover'] = env('OSS_URL').$val['cover'];
        }

        return response()->json(['code'=>'200','msg' => '请求成功','data'=>$data]);

    }

    /**
     * Get a JWT via given credentials.
     *  活动详情
     * @return \Illuminate\Http\JsonResponse
     */
    public function detail(Request $request)
    {

        $activity_id = $request->post('activity_id');

        $data = ActivityModel::where(['id'=>$activity_id])->first();

        $data['cover'] = env('OSS_URL').$data['cover'];

        return response()->json(['code'=>'200','msg' => '请求成功','data'=>$data]);

    }

}
